package com.lp.zyll.controller;


import com.lp.zyll.redis.RedisCRUD;
import com.lp.zyll.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("/demo")
public class DemoController {


    @Autowired
    RedisCRUD redisCRUD;


    @GetMapping("test1")
    public ResponseEntity test1(String name){
        redisCRUD.set("name",name);


        return ResponseEntity.ok(name);
    }


    @GetMapping("test2")
    public ResponseEntity test2(String name){

        String s = redisCRUD.get(name);

        return ResponseEntity.ok(s);
    }

    @GetMapping("test3")
    public ResponseEntity test3(String name1,String name2){

        HashMap map = new HashMap();

        map.put("t1",name1);
        map.put("t2",name2);

        redisCRUD.setObject("map",map,60);

        return ResponseEntity.ok(map);
    }

    @GetMapping("test4")
    public ResponseEntity test3(){

        HashMap map = redisCRUD.getObject("map", HashMap.class);
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(map);
    }

}
